package com.cmcc.shared.data

import com.cmcc.shared.SdkManager
import com.cmcc.shared.config.SharedConfig
import com.cmcc.shared.network.RetrofitRequest
import com.cmcc.shared.network.interceptor.HttpLoggingInterceptor
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory

class Network private constructor() {

    var apiService = RetrofitRequest.Builder().baseUrl(SharedConfig.APP_DOMAIN)
        .setLogLevel(HttpLoggingInterceptor.Level.BODY)
        .addHeader("Content-Type", "application/json")
        .addHeader("Accept-Language", when (SdkManager.getLanguage()) {
            0 -> "en-US"
            1 -> "zh-CN"
            2 -> "zh-HK"
            else -> "zh-HK"
        })
        .addCallAdapterFactory(CoroutineCallAdapterFactory())
        .build()
        .createService(PlatformApiService::class.java)


    companion object {
        @Volatile
        private var instance: Network? = null

        fun getInstance(): Network {
            return instance ?: synchronized(this) {
                instance ?: Network().also { instance = it }
            }
        }
    }

}
